Skip to content

feat(dupes): interactive duplicate-person review - #212

Merged
2000game merged 24 commits into
mainfrom
worktree-agent-a8b024c30ad4b62d4
Nov 11, 2026
Merged

2000game merged 24 commits into
mainfrom
worktree-agent-a8b024c30ad4b62d4

Conversation

@2000game

@2000game 2000game commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds ct dupes scan | review | export-finance, an interactive-only workflow for finding and merging duplicate person records.

  • Detector: match classes (exact, nameswap, middlename, firsttoken, shortform, diminutive, fuzzy, ct), tiers T1-T3, vetoes (relationship, placeholder, birthday, sex).

  • Review in the browser (ct dupes review, default): a local page modelled on ChurchTools' own duplicate page and "Dubletten überprüfen" dialog. Original (the older person, lower id) vs Duplikat, clickable arrows per field, × to clear, a star for the default email, a pager, and "Keine Dublette". Zusammenführen merges right away, with no extra confirm step. After an action the dialog stays at the same position in the pager.

    • Email rows carry their contact type from masterdata ("E-Mail (Privat)").
    • Campus, status, sex and Bereich show masterdata names. Dates read as in ChurchTools (DD.MM.YYYY).
    • Bereich is a list: when the two differ, both are kept by default (beide).
    • The server binds to 127.0.0.1 only, uses a token in the URL fragment and a Host check, has a strict CSP, and the page holds no person data.
  • Terminal view (--tui, Ink, loaded lazily) with the same choices.

  • Merge via the API (PATCH /persons/{original}/merge/{duplicate}), with a body in the shape ChurchTools' own UI sends. Shared groups are cleaned up first, since ChurchTools refuses the merge otherwise: dynamic groups drop the Duplikat; static groups keep the Original's membership with chosen member values (earlier join date by default).

  • Refusals: the HTTP status, the rejected field names and ChurchTools' messageKey are shown, never values. The refusal to merge a person with permissions of their own (error.forbidden.merge-authorized-person) is explained in plain words.

  • Personal-data guard: against protected envs, ct dupes requires a TTY on stdin and stdout and no AI-agent session. There is no bypass flag.

  • Local store outside any repo (0700/0600), with a JSONL audit log, --redact, and no person data in errors.

  • Finance export (ct-cli.dupes.optigem-merges/1) as CSV and JSON. Each row has:

    • both persons (id, name and Optigem ID before the merge);
    • the surviving person and the Optigem ID it now carries (leading), plus the other ID (orphaned).

    Finance decides which ID stays in Optigem.

  • Docs: new handbook page docs/handbuch/dupes.md. README and CONTRIBUTING are updated: structure commands never touch people; ct dupes does, explicitly and interactively.

Verification

format:check, lint, typecheck, test (1442 passed), build and docs staleness pass locally.

On a dev instance with fictitious persons:

  • Merges ran end to end in the browser view: field choices, emails with types, Bereich both, Optigem ID choice, and the shared static plus dynamic group clean-up.
  • The finance export rows were checked.
  • The 403 for a person with permissions was reproduced and its key surfaced.
  • Seed data is cleaned up after testing.

Not verified

  • Behaviour against a real protected env.
  • The merge endpoint is Beta in the OpenAPI spec and may change between ChurchTools releases.

…t-finance)

Adds the ct dupes command family: a detector with match classes and tiers,
relationship-based suppression, an interactive review with dynamic and
static group handling, a local audit log, and an Optigem finance export.
Runs against protected envs only in a human terminal session. v1 opens
the ChurchTools merge page instead of calling the merge API.
- resolveRelationshipTypes throws instead of falling back to fixed ids
- scan keeps earlier dismissed/merged decisions for pairs that still turn up
- CT-suggested pairs share one scoring context; dynamic group ids fetched once
- merge URL rendered with a function replacer, trailing slash stripped
- cleanName keeps letters of any script
- review says group changes stay applied when stopping before the merge page
@2000game
2000game marked this pull request as draft November 9, 2026 11:22
ChurchTools refuses a merge (403) while both persons share a group. Before the
merge, the Duplikat is removed from shared dynamic groups; for other groups the
Original's membership takes the chosen values (earlier join date, empty values
filled from the Duplikat, conflicts chosen per row) and then the Duplikat is
removed. The merge preview's groupsDiff.both is a list of group ids.
Verified end to end on a dev instance.
…e page

`ct dupes review` now starts a local web server on 127.0.0.1 and opens a
page that mirrors ChurchTools' duplicate list and "Dubletten überprüfen"
dialog, with the ct dupes additions (tiers, match class, Optigem, shared
groups and their membership values). Values are chosen by clicking a side,
the confirm box lists every change, and the dialog moves on to the next
open pair. `--tui` keeps the terminal view, `--no-open` only prints the URL.

The server takes a random token from the URL fragment as a header, refuses
foreign Host headers, sends no data with the page, and applies --redact
server-side. Merges go through the same executeMerge as the terminal view.
…view

As in ChurchTools' dialog, each side with a value gets an arrow button that
takes it; the chosen one is outlined. On email rows the arrow includes or
excludes the address. Departments get their own Bereich section and show
their masterdata names (in the terminal view too) instead of ids.
The dialog already shows every choice, as ChurchTools' own does, so
Zusammenführen now merges right away. The terminal view keeps its confirm.
…and page

- Group cleanup is idempotent (404 on the Duplikat's DELETE counts as done); after a
  failed merge that already changed groups the pair is re-read and the dialog reloads it,
  and the messages say what was already changed.
- Only a 404 on GET /persons/{id} means "person gone"; recovered merges need a
  merge-started entry, a missing loser and a loadable survivor.
- Finance export includes every merge that orphaned an Optigem ID, also when the field
  was cleared.
- One GET per person when loading a pair; dynamic group ids cached per client.
- export-finance --out refuses git work trees and writes 0600 files.
- Agent guard checks full ancestor command lines and runtime markers of more tools, and
  fails closed when the process check cannot run.
- Web page: dialog cannot close mid-request and never swallows results, token survives
  reload via sessionStorage, readable narrow layout, persistent search input, pager
  follows the search filter.
@2000game
2000game marked this pull request as ready for review November 11, 2026 10:35
@2000game
2000game merged commit b80d1ce into main Nov 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant